stylecontext: Handle querying the wrong state better
authorBenjamin Otte <otte@redhat.com>
Tue, 21 Oct 2014 00:06:46 +0000 (02:06 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 21 Oct 2014 01:03:28 +0000 (03:03 +0200)
When a getter function (like get_color()) is called and the passed in
state doesn't match the current state returned via get_state(), we used
to do a trick: We called save()/set_state() on the context before
getting the values.

Unfortunately, since 3a337156d11a86c7a88f1f30a09276fdf6f63008 this
has the unfortunate side effect that it also creates a child element.
This breaks various old codebases (spinbutton has been fixed in
998feeb2bc3e37275cfe915e128179d2704ca9c8, Webkit is fixed in
https://bugs.webkit.org/show_bug.cgi?id=137803 ) unfortunately.

So instead, look up the values manually ensuring that no child element
is created but the correct state is used.

gtk/gtkstylecontext.c

index 3752ce3be3e7f6ce0018d69e4b53a82a31c2fc73..4cb834819e0e54418a02e3166c911b1c659658d1 100644 (file)
@@ -738,15 +738,17 @@ static GtkCssComputedValues *
 style_values_lookup_for_state (GtkStyleContext *context,
                                GtkStateFlags    state)
 {
+  GtkCssNodeDeclaration *decl;
   GtkCssComputedValues *values;
 
   if (gtk_css_node_declaration_get_state (context->priv->info->decl) == state)
     return g_object_ref (style_values_lookup (context));
 
-  gtk_style_context_save (context);
-  gtk_style_context_set_state (context, state);
-  values = g_object_ref (style_values_lookup (context));
-  gtk_style_context_restore (context);
+  decl = gtk_css_node_declaration_ref (context->priv->info->decl);
+  gtk_css_node_declaration_set_state (&decl, state);
+  values = _gtk_css_computed_values_new ();
+  build_properties (context, values, decl, NULL);
+  gtk_css_node_declaration_unref (decl);
 
   return values;
 }